From: Colin Walters Date: Tue, 11 May 2010 15:55:33 +0000 (-0400) Subject: Rework compare to take into account closed windows X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~10077 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=b736f52037006507932d0bf56fd21eb9f28ffd0b;p=gnome-shell.git Rework compare to take into account closed windows The API docs for ShellApp claimed it sorted by the last time the user interacted with the app, but if one closed a window, then we would fall back to comparing against a possibly much older timestamp from another window. Fix this by just keeping a user time per app. Also clean up the comparison function to explicitly check the state instead of deferring to the window list. https://bugzilla.gnome.org/show_bug.cgi?id=618378 --- diff --git a/src/shell-app.c b/src/shell-app.c index bf01a5292..b62799491 100644 --- a/src/shell-app.c +++ b/src/shell-app.c @@ -25,6 +25,8 @@ struct _ShellApp ShellAppInfo *info; + guint32 last_user_time; + guint workspace_switch_id; GSList *windows; @@ -560,10 +562,9 @@ shell_app_is_on_workspace (ShellApp *app, * @other: A #ShellApp * * Compare one #ShellApp instance to another, in the following way: + * - Running applications sort before not-running applications. * - If one of them has visible windows and the other does not, the one * with visible windows is first. - * - If one has no windows at all (i.e. it's not running) and the other - * does, the one with windows is first. * - Finally, the application which the user interacted with most recently * compares earlier. */ @@ -572,7 +573,13 @@ shell_app_compare (ShellApp *app, ShellApp *other) { gboolean vis_app, vis_other; - GSList *windows_app, *windows_other; + + if (app->state != other->state) + { + if (app->state == SHELL_APP_STATE_RUNNING) + return -1; + return 1; + } vis_app = shell_app_has_visible_windows (app); vis_other = shell_app_has_visible_windows (other); @@ -587,10 +594,7 @@ shell_app_compare (ShellApp *app, else if (!app->windows && other->windows) return 1; - windows_app = shell_app_get_windows (app); - windows_other = shell_app_get_windows (other); - - return meta_window_get_user_time (windows_other->data) - meta_window_get_user_time (windows_app->data); + return other->last_user_time - app->last_user_time; } ShellApp * @@ -642,6 +646,8 @@ shell_app_on_user_time_changed (MetaWindow *window, GParamSpec *pspec, ShellApp *app) { + app->last_user_time = meta_window_get_user_time (window); + /* Ideally we don't want to emit windows-changed if the sort order * isn't actually changing. This check catches most of those. */ @@ -668,6 +674,8 @@ void _shell_app_add_window (ShellApp *app, MetaWindow *window) { + guint32 user_time; + if (g_slist_find (app->windows, window)) return; @@ -676,6 +684,10 @@ _shell_app_add_window (ShellApp *app, g_signal_connect (window, "notify::user-time", G_CALLBACK(shell_app_on_user_time_changed), app); app->window_sort_stale = TRUE; + user_time = meta_window_get_user_time (window); + if (user_time > app->last_user_time) + app->last_user_time = user_time; + if (app->state != SHELL_APP_STATE_RUNNING) shell_app_state_transition (app, SHELL_APP_STATE_RUNNING);